from langchain_community.chat_models import ChatTongyi
from langchain.schema import SystemMessage,HumanMessage
import os


os.environ["DASHSCOPE_API_KEY"] = 'sk-965dc39b016c49ecbe29de180f4db2b6'
chat = ChatTongyi(templature=0)
#使用call方法
res = chat([
    HumanMessage(content='你是谁?')
])
print(res)
print(type(res))

#使用predict方法
res = chat.predict('你是谁?')
print(res)
print(type(res))

#使用predict message方法
res = chat.predict_messages([
    SystemMessage(content='Your identity is as a writer'),
    HumanMessage(content='你是谁?')
])
print(res)
print(type(res))
#使用batch方法
batch = [
    [SystemMessage(content='Your identity is as a writer'),
    HumanMessage(content='你是谁?')
     ],
[SystemMessage(content='Your identity is as a doctor'),
    HumanMessage(content='你是谁?')]
]
res = chat.generate(batch)
for data in res.generations:
    print(data)
    print(data[0])
